package br.elsa.survey.services.listeners;

import javax.enterprise.event.Observes;
import javax.inject.Inject;

import br.elsa.survey.domain.survey.Survey;
import br.elsa.survey.services.events.SurveyCreatedEvent;
import br.elsa.survey.statistics.Statistics;

/**
 * Component that listen to business events over {@link Survey} entities
 * 
 * @author diego
 * @since 2010-11-19
 */
public class SurveyEventListener {

	@Inject
	private Statistics statisticsService;

	public SurveyEventListener() {

	}

	/**
	 * Used by test classes to inject Mock dependencies
	 * 
	 * @param statistics
	 */
	public SurveyEventListener(Statistics statistics) {
		this.statisticsService = statistics;
	}

	/**
	 * Executed when {@link SurveyCreatedEvent} is raised
	 * 
	 * @param event The event data holding a reference to the created {@link Survey}
	 */
	public void onSurveyCreated(@Observes SurveyCreatedEvent event) {
		statisticsService.loadStatistics();
	}
}
